/**
 * tarside-ftp -- A simple FTP client, using the ANSI C and GTK+.
 * Copyright (C) 2011  degui.chen <degui.chen@qq.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "info.h"

static short int port_model = 0; // 1 port, 0 pasv
short int get_ftp_model() {
	return port_model;
}
void set_ftp_port_model() {
	port_model = 1;
}
void set_ftp_pasv_model() {
	port_model = 0;
}

static int _main_connect;
static void _close_connect() {
	printf("close connect %i \n", _main_connect);
	close(_main_connect);
}
int open_connect(char* ip, int port) {
	if (_main_connect > 0) {
		_close_connect();
	}
	atexit(_close_connect);
	_main_connect = create_connect(ip, port);
	return _main_connect;
}

static unsigned int s_port;
unsigned int get_port() {
	if (s_port < 1024) {
		s_port = 48569;
	}
	return s_port;
}
void port_plus() {
	s_port++;
}

static char local_current_dir[255] = { '\0' };

void set_local_current_dir(char* path) {
	if (file_exists(path)) {
		strcpy(local_current_dir, path);
	}
}
char* get_local_current_dir() {
	return local_current_dir;
}

int file_exists(char *filename) {
	return (access(filename, 0) == 0);
}
